/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package heartnew;

import java.util.ArrayList;
import java.util.Random;

/**
 *
 * @author ThuyHuynh
 */
public class Board {

    private ArrayList<Player> listplayer;//danh sach nguoi choi
    private ArrayList<Turn> cardinturn;//danh sach la bai 1 luot di
    private ArrayList<Card> listcard;//danh sach bai da danh ra 
    int turn;
    private int board;
    public Board() {


        listplayer = new ArrayList<>();
        cardinturn = new ArrayList<>();
        listcard = new ArrayList<>();
        InitCard();

        RandomCard();
        initPlayer();
        InitCardPlayer();
        InitTurn();
        board = 1;



    }

    public Board(ArrayList<Player> listplayer, ArrayList<Turn> cardinturn, ArrayList<Card> listcard) {
        this.listplayer = listplayer;
        this.cardinturn = cardinturn;
        this.listcard = listcard;
    }

    public Board(Board b) {
        listplayer = b.listplayer;
        cardinturn = b.cardinturn;
        listcard = b.listcard;
    }
//tao 52 la bai 

    public void InitCard() {
        for (int i = 1; i <= 13; i++) {
            for (int j = 1; j <= 4; j++) {
                Card c = new Card((short) i, (short) j);
                listcard.add(c);
            }
        }
    }

    public void InitTurn() {
        cardinturn.clear();
    }
    public void ClearCard()
    {
        for(Player p : listplayer)
        {
            p.ClearCard();
        }
        cardinturn.clear();
      
      
    }
    public void RandomCard() {
        Random rd = new Random();
        for (int i = 1; i <= 100; i++) {
            int a = rd.nextInt(listcard.size());
            int b = rd.nextInt(listcard.size());
            Card temp = listcard.get(b);//temp=b,b=a,a=temp
            listcard.set(b, listcard.get(a));
            listcard.set(a, temp);
        }
    }

    public void Init() {
        ClearCard();
    }

    public void initPlayer() {
        for (int i = 0; i <= 3; i++) {
            Player p = new Player();
            p.setIdplayer(i);
            p.setScore(0);
            listplayer.add(p);
        }
    }

    public void InitCardPlayer() {

        for (int i = 0; i < 4; i++) {
            Player p = listplayer.get(i);
//            p.setCardinhand(null);
            p.setIsturn(0);//chua den luot
            ArrayList<Card> cardinhandtemp = new ArrayList<Card>();
            System.out.println("nguoi choi thu " + (i + 1));
            for (int j = i * 13; j < 13 * (i + 1); j++) {
                cardinhandtemp.add(listcard.get(j));//add 13 la bai trong 54 la bai vao nguoi choi thu i
                System.out.println("num=" + listcard.get(j).getNumber() + ";" + listcard.get(j).getRank());

            }
            p.setCardinhand(cardinhandtemp);
        }



    }

    /**
     * @return the listplayer
     */
    public ArrayList<Player> getListplayer() {
        return listplayer;
    }

    /**
     * @param listplayer the listplayer to set
     */
    public void setListplayer(ArrayList<Player> listplayer) {
        this.listplayer = listplayer;
    }

    /**
     * @return the cardinturn
     */
    public ArrayList<Turn> getCardinturn() {
        return cardinturn;
    }

    /**
     * @param cardinturn the cardinturn to set
     */
    public void setCardinturn(ArrayList<Turn> cardinturn) {
        this.cardinturn = cardinturn;
    }

    /**
     * @return the listcard
     */
    public ArrayList<Card> getListcard() {
        return listcard;
    }

    /**
     * @param listcard the listcard to set
     */
    public void setListcard(ArrayList<Card> listcard) {
        this.listcard = listcard;
    }

    /**
     * @return the board
     */
    public int getBoard() {
        return board;
    }

    /**
     * @param board the board to set
     */
    public void setBoard(int board) {
        this.board = board;
    }
}
